blob: 152721cfe15d9029642732c7e32fd3f960a516b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import * as React from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { Shell } from "@/components/shell";
import { ErrorBoundary } from "@/components/error-boundary";
import { getDashboardData } from "@/lib/dashboard/service";
import { DashboardClient } from "@/lib/dashboard/dashboard-client";
// 데이터 fetch 시 비동기 함수 호출 후 await 하므로 static-pre-render 과정에서 dynamic-server-error 발생.
// 따라서, dynamic 속성을 force-dynamic 으로 설정하여 동적 렌더링 처리
// getDashboardData 함수에 대한 Promise를 넘기는 식으로 수정하게 되면 force-dynamic 선언을 제거해도 됨.
export const dynamic = 'force-dynamic'
export default async function IndexPage() {
// domain을 명시적으로 전달
const domain = "sales";
try {
// 서버에서 직접 데이터 fetch
const dashboardData = await getDashboardData(domain);
return (
<Shell className="gap-2">
<DashboardClient initialData={dashboardData} />
</Shell>
);
} catch (error) {
console.error("Dashboard data fetch error:", error);
return (
<Shell className="gap-2">
<div className="flex items-center justify-center py-12">
<div className="text-center space-y-2">
<p className="text-destructive">데이터를 불러오는데 실패했습니다.</p>
<p className="text-muted-foreground text-sm">{error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다."}</p>
</div>
</div>
</Shell>
);
}
}
function DashboardSkeleton() {
return (
<div className="space-y-6">
{/* 헤더 스켈레톤 */}
<div className="flex items-center justify-between">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-72" />
</div>
<Skeleton className="h-10 w-24" />
</div>
{/* 요약 카드 스켈레톤 */}
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
{[...Array(4)].map((_, i) => (
<div key={i} className="space-y-3 p-6 border rounded-lg">
<div className="flex items-center justify-between">
<Skeleton className="h-4 w-16" />
<Skeleton className="h-4 w-4" />
</div>
<Skeleton className="h-8 w-12" />
<Skeleton className="h-3 w-20" />
</div>
))}
</div>
{/* 차트 스켈레톤 */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{[...Array(2)].map((_, i) => (
<div key={i} className="space-y-4 p-6 border rounded-lg">
<div className="space-y-2">
<Skeleton className="h-6 w-32" />
<Skeleton className="h-4 w-48" />
</div>
<Skeleton className="h-[300px] w-full" />
</div>
))}
</div>
{/* 탭 스켈레톤 */}
<div className="space-y-4">
<Skeleton className="h-10 w-64" />
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
{[...Array(6)].map((_, i) => (
<div key={i} className="space-y-4 p-6 border rounded-lg">
<Skeleton className="h-6 w-32" />
<div className="space-y-3">
<div className="flex justify-between">
<Skeleton className="h-4 w-16" />
<Skeleton className="h-4 w-12" />
</div>
<div className="flex gap-2">
<Skeleton className="h-6 w-16" />
<Skeleton className="h-6 w-16" />
<Skeleton className="h-6 w-16" />
</div>
<Skeleton className="h-2 w-full" />
</div>
</div>
))}
</div>
</div>
</div>
);
}
|